<template>
  <Modal :value="value" width="500" @on-ok="submitForm" @on-cancel="onCancle">
    <template #header>
      <p style="color: #f60; text-align: center">
        <Icon type="ios-information-circle"></Icon>
        <span>{{ data._id ? "编辑" : "添加" }}数据</span>
      </p>
    </template>

    <div style="text-align: center">
      <Form :model="data" :label-width="80">
        <FormItem label="模块:">
          <Input v-model="data.mode" placeholder="请输入模块"></Input>
        </FormItem>
        <FormItem label="通知内容:">
          <Input v-model="data.content" placeholder="请输入通知内容"></Input>
        </FormItem>
      </Form>
    </div>
  </Modal>
</template>
<script>
import { add, update } from "@/api/notice";
export default {
  name: "EditNotice",
  data() {
    return {
      model: false,
    };
  },
  computed: {
    data() {
      let e = this.editData;
      return {...e};
    },
  },
  props: {
    editData: {
      default: null,
      type: Object,
    },
    value: {
      default: false,
      type: Boolean,
    },
  },
  methods: {
    onCancle() {
      this.$emit("input", false);
    },
    submitForm() {
      if (!this.data._id) {
        add(this.data).then((res) => {
          if (res.data.errCode == 0) {
            this.$Notice.success({
              title:res.data.errMsg
            });
            this.data._id = res.data.data.id;
            this.$emit("add", this.data);
          } else {
            this.$Notice.error({
              title:res.data.errMsg
            });
          }
        });
      } else {
        update(this.data).then((res) => {
          if (res.data.errCode == 0) {
            this.$Notice.success({
              title:res.data.errMsg
            });
            this.$emit("update", this.data);
          } else {
            this.$Notice.error({
              title:res.data.errMsg
            });
          }
        });
      }
    },
  },
};
</script>